package com.ny.demo508;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class BufferedWriterExample {
    public static void main(String[] args) {
        String data = "这是要保存到文件中的数据";
        try (BufferedWriter writer = new BufferedWriter(new FileWriter("test.txt"))) {
            writer.write(data);
            System.out.println("数据已成功保存到文件");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
